import { uniFetch } from "../http.js";
import md5 from "md5";

export const login = (username, password) => {
  return new Promise((resolve, reject) => {
    const md5Password = md5(password);
    uni.request({
      url: `/blade-auth/oauth/token?tenantId=000000&username=${username}&password=${md5Password}&grant_type=password&scope=all&type=account`,
      method: "post",
      header: {
        Authorization: "Basic c2FiZXIzOnNhYmVyM19zZWNyZXQ=",
        "ngrok-skip-browser-warning": "true",
        "content-type": "application/json",
        "Tenant-Id": "000000",
      },
      success: (res) => {
        if (res.statusCode === 200) {
          resolve(res.data);
        } else {
          reject(res);
        }
      },
      fail: (err) => {
        reject(err);
      },
    });
  });
};

export const getCaptcha = () => {
  return uniFetch({
    url: "/blade-device/deviceInfo/list",
    method: "GET",
    istoast: false,
  });
};
